﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;

namespace AirlineClient
{
    class ClientProcess
    {
        HttpClient client = new HttpClient();
        TicketType departTicketSelected = null;

        public TicketType DepartTicketSelected
        {
            get { return departTicketSelected; }
            set { departTicketSelected = value; }
        }
        TicketType arriveTicketSelected = null;

        public TicketType ArriveTicketSelected
        {
            get { return arriveTicketSelected; }
            set { arriveTicketSelected = value; }
        }

        public ClientProcess()
        { 
            client.BaseAddress = new Uri("http://localhost:28772/");
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        }

        public List<List<FlightInfo>> GetAllFlightOfVietNamAirline(Info searchInfo)
        {
            List<List<FlightInfo>> result = new List<List<FlightInfo>>();

            string url = "api/VietnamAirline/?currency="+searchInfo._Currency+"&direction="+searchInfo._FlightStructure+"&depCity="+searchInfo._DepartCity+"&depDay="+searchInfo._DepDay+"&depMonth="+searchInfo._DepMonth+
                "&retCity="+searchInfo._ArriveCity+"&retDay="+searchInfo._ReturnDay+"&retMonth="+searchInfo._ReturnMonth+"&ADT="+searchInfo._ADT+"&CHD="+searchInfo._CHD+"&INFANT="+searchInfo._INFANT;

            HttpResponseMessage response = client.GetAsync(url).Result;
            if(response.IsSuccessStatusCode)
            {
                result = response.Content.ReadAsAsync<List<List<FlightInfo>>>().Result;
            }

            return result;
        }



        public string GetBookingCode(string outCode, string inCode, string direction, string depCity, string depDay, string depMonth, string arrCity, string arrDay,
                            string arrMonth, string ADT, string prefix, string middleName, string lastName, string mobile_CityCode, string mobile_PhoneNumber,
                            string homeCode, string homeNumber, string email, string totalPrice, string baseFare, string bankName)
        {
            string url = "api/VietnamAirline/?&outCode=" + outCode + "&inCode=" + inCode + "&direction=" + direction + "&depCity=" + depCity +
                "&depDay=" + depDay + "&depMonth=" + depMonth + "&arrCity=" + arrCity + "&arrDay=" + arrDay + "&arrMonth=" + arrMonth + "&ADT=" + ADT + "&prefix=" + prefix +
                "&middleName=" + middleName + "&lastName=" + lastName + "&mobile_CityCode=" + mobile_CityCode + "&mobile_PhoneNumber=" + mobile_PhoneNumber +
                "&homeCode=" + homeCode + "&homeNumber=" + homeNumber + "&email=" + email + "&totalPrice=" + totalPrice + "&baseFare=" + baseFare + "&bankName=" + bankName;

            HttpResponseMessage response = client.GetAsync(url).Result;
            if (response.IsSuccessStatusCode)
            {
                string code = response.Content.ReadAsAsync<string>().Result;
                return code;
            }
            return null;
        }

        public List<List<Flight>> GetAllFlightOfJetStar(Info info)
        {
            List<List<Flight>> result = new List<List<Flight>>();

            string url = "api/JetStar/?structure="+info._FlightStructure+"&depCity="+info._DepartCity+"&depTime="+info._DepartDay
                +"&arrCity="+info._ArriveCity+"&arrTime="+info._ArriveDay+"&currency="+info._Currency+"&ADT="+info._ADT+"&CHD="+info._CHD+"&INFANT="+info._INFANT;

            HttpResponseMessage response = client.GetAsync(url).Result;
            if (response.IsSuccessStatusCode)
            {
                result = response.Content.ReadAsAsync<List<List<Flight>>>().Result;
            }

            return result;
        }
    }
}
